package com.kratos.designdemo.service;

import com.kratos.designdemo.controller.vo.OrderVo;
import com.kratos.designdemo.entity.Order;
import com.kratos.designdemo.enums.OrderStatusEnum;
import org.springframework.beans.BeanUtils;

/**
 * @author kratos
 * @date 2022-06-09 13:52:40
 * <p>
 * 订单状态抽象类
 * 抛出的RuntimeException 需要替换成业务异常
 */
public abstract class OrderStatusAbstract {


    public Order check(OrderVo vo) {
        if (null == vo) {

            throw new RuntimeException("参数不能为空");
        }

        if (null == vo.getOrderNo()) {

            throw new RuntimeException("订单号不能为空");
        }
        //查询数据库，获取订单信息。
        Order dbOrder =/* OrderMapper.selectOne(vo.getOrderNo())*/ new Order();
        if (null == dbOrder) {

            throw new RuntimeException("参数错误");
        }

        Order order = new Order();
        BeanUtils.copyProperties(dbOrder, order);

        /*if (OrderStatusEnum.isExtisCode(order.getStatus())) {

            throw new RuntimeException("数据错误");
        }*/
        if (OrderStatusEnum.isExtisCode(vo.getStatus())) {

            throw new RuntimeException("数据错误");
        }

        return order;
    }
}
